/**
 * 
 */
package calculation;

/**
 * @author Michael
 *
 */
public class MultiplicationExcludeSelf {


	public static int[] multiply(int[] a) {
		assert (null != a);
		if (a.length == 1) return a;
		
		int[] result = new int[a.length];
		for (int i = 0; i < result.length; i ++) { result[i] = 1; }
		int left = 1;
		int right = 1;
		for (int i = 0; i < a.length; ++i) {
			result[i] *= left;
			result[a.length - 1- i] *= right;
			left *= a[i];
			right *= a[a.length - 1 - i];
		}
		
		return result;
	}
	
	/**
	 * 
	 */
	public MultiplicationExcludeSelf() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//int[] a = { 1, 2, 3, 4, 5 };
		int[] a = {10};
		int[] b = multiply(a);
		for (int i = 0; i < b.length; i++) {
			System.out.println(b[i]);
		}

	}

}
